You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mimic-fn

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mimic-fn

Make a function mimic another one

1.2.0
Source
npmnpm
Version published
Weekly downloads
82M
-3.06%
Maintainers
1
Weekly downloads
 
Created

What is mimic-fn?

The mimic-fn package is a utility that allows you to copy the properties of a function onto another function. This includes the function's name, length (the number of arguments it expects), and custom properties. It is useful when you want to wrap a function without losing its original properties, which can be important for debugging, introspection, and certain function-based APIs that rely on these properties.

What are mimic-fn's main functionalities?

Copying function properties

This feature allows you to copy all properties from the original function to the wrapper function, including the function name and custom properties.

const mimicFn = require('mimic-fn');

function original() {}
original.customProp = 'hello';

function wrapper() {
  return original();
}

console.log(wrapper.name); // 'wrapper'
console.log(wrapper.customProp); // undefined

mimicFn(wrapper, original);

console.log(wrapper.name); // 'original'
console.log(wrapper.customProp); // 'hello'

Other packages similar to mimic-fn

Keywords

function

FAQs

Package last updated on 02 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts